

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_If_RT : RT_Node
    {
        public RT_SingleValuePort Condition_RT;

        public RT_SingleValuePort IfTrue_RT;

        public RT_SingleValuePort IfFalse_RT;

        public RT_SingleValuePort Result_RT;

        public Node_If_RT(Node_If sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Condition_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Condition, this);

            IfTrue_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.IfTrue, this);

            IfFalse_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.IfFalse, this);

            Result_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Result, this);
            Result_RT.OnGetValue = GetResult;
        }

        public AValue GetResult(DAG_Executor executor)
        {
            bool cond = Condition_RT.GetValue(executor).ToBoolean().Item2;
            if (cond)
            {
                Result_RT.SourceValue.Assign(IfTrue_RT.GetValue(executor));
            }
            else
            {
                Result_RT.SourceValue.Assign(IfFalse_RT.GetValue(executor));
            }

            return Result_RT.SourceValue;
        }
    }
}